// @formatter:off
/**
 * @file WCShortCuts.js
 * @author Alejandro Dario Simi
 * @date $Date: 2013-07-24 01:55:33 +0000 (Wed, 24 Jul 2013) $
 *
 * $Id: WCShortCuts.js 99 2013-07-24 01:55:33Z daemonraco@gmail.com $
 * $URL: http://wcomix.googlecode.com/svn/tags/wcomix-1.0.0.1/includes/WCShortCuts.js $
 */
// @formatter:on

WCShortCuts = {
	//
	// Protected variables.
	_triggers: [],
	//
	// Public methods.
	add: function(key, callback) {
		this._triggers[key] = callback;
	},
	keyEventToText: function(e) {
		var key = (e.ctrlKey ? 'CTRL+' : '') + (e.altKey ? 'ALT+' : '') + (e.shiftKey ? 'SHIFT+' : '');
		switch(e.keyCode) {
			case 27:
				code = "ESC";
				break;
			default:
				code = String.fromCharCode(e.which);
				break;
		}
		return key + code;
	},
	remove: function(key) {
		if(this._triggers[key]) {
			delete this._triggers[key];
		}
	},
	reset: function() {
		this._triggers = [];
	},
	startExceptions: function() {
		$(".WCSortCuts_avoid,.WCSortCuts_monitor").keyup(function(e) {
			e.stopPropagation();
		});
		$(".WCSortCuts_monitor").keyup(function(e) {
			var id = $(e.currentTarget).attr("id");
			if(id) {
				id = "'" + id + "' monitor: ";
			} else {
				id = "monitor: ";
			}
			console.log(id + WCShortCuts.keyEventToText(e));
		});
	},
	start: function() {
		this.startExceptions();
		$(document).keyup(function(e) {
			var key = WCShortCuts.keyEventToText(e);
			if(WCShortCuts._triggers[key]) {
				WCShortCuts._triggers[key](key, e);
			}
		});
	}
	//
	// Protected methods.
};
